package com.zrq.secondkill.service.impl;

import com.zrq.secondkill.service.CacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 *对redis的封装(适配器),使之符合{@link CacheService}接口
 * @author zrq
 */
@Service("redisCacheServiceImpl")
public class RedisCacheServiceImpl implements CacheService {

    final
    RedisTemplate redisTemplate;

    public RedisCacheServiceImpl(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void set(String key, Object value, long expire, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key,value,expire,timeUnit);
    }

    @Override
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
